package com.niguang.govt.admin.common.pojo;

import com.niguang.govt.admin.common.constant.ResultCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 *
 */
@Getter
@Setter
@NoArgsConstructor
public class Result<T> {

    private String code = "";

    private String msg = "";

    private String userMsg = "";

    private T data;

    public Result(ResultCode resultCode) {
        this.code = resultCode.getValue();
        this.msg = resultCode.getDesc();
    }

    public Result(ResultCode resultCode, T data) {
        this.code = resultCode.getValue();
        this.msg = resultCode.getDesc();
        this.data = data;
    }

    public Result(ResultCode resultCode, String userMsg, T data) {
        this.code = resultCode.getValue();
        this.userMsg = userMsg;
        this.data = data;
    }

    public Result(ResultCode resultCode, String msg, String userMsg, T data) {
        this.code = resultCode.getValue();
        this.msg = msg;
        this.userMsg = userMsg;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<>(ResultCode.SUCCESS);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultCode.SUCCESS, data);
    }


    public static <T> Result<T> failed() {
        return new Result<>(ResultCode.FAILED, ResultCode.FAILED.getDesc(), null);
    }

    public static <T> Result<T> failed(String userMsg) {
        return new Result<>(ResultCode.FAILED, userMsg, null);
    }

    public static <T> Result<T> build(ResultCode resultCode) {
        return new Result<>(resultCode);
    }

    public static <T> Result<T> build(ResultCode resultCode, T data) {
        return new Result<>(resultCode, data);
    }

    public static <T> Result<T> build(ResultCode resultCode, String msg, String userMsg) {
        return new Result<>(resultCode, msg, userMsg, null);
    }

    public static <T> Result<T> build(ResultCode resultCode, String msg, T data) {
        return new Result<>(resultCode, msg, "", data);
    }

    public static <T> Result<T> build(ResultCode resultCode, String msg, String userMsg, T data) {
        return new Result<>(resultCode, msg, userMsg, data);
    }

    public static <T> Result<T> build(ResultCode resultCode, String userMsg) {
        return new Result<>(resultCode, "", userMsg, null);
    }

}
